package com.example.houduan.Service.Impl;

import com.example.houduan.Mapper.DrugMapper;
import com.example.houduan.Pojo.Drug;
import com.example.houduan.Service.DrugService;
import com.example.houduan.Utils.PageModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DrugServiceImpl implements DrugService {

    @Autowired
    DrugMapper drugMapper;

    @Override
    public PageModel getDrugPage(int num,int size) {
        int count = drugMapper.selectDrugCount();
        PageModel pm=new PageModel(num,count,size);
        pm.setList(drugMapper.selectDrugLimit((num-1)*size,size));
        return pm;
    }

    @Override
    public List<Drug> getDrugByConditions(Integer drug_id, String drug_name, String company_name) {
        return drugMapper.selectDrugByConditions(drug_id,drug_name,company_name);
    }


    @Override
    public int addDrug(Drug drug) {
        return drugMapper.insertDrug(drug);
    }

    @Override
    public int deleteDrug(int drug_id) {
        return drugMapper.deleteDrug(drug_id);
    }

    @Override
    public int updateDrug(Drug drug) {
        return drugMapper.updateDrug(drug);
    }
}
